home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <system.h>
- #include <io.h>
-
-
-
- void f1(), f2();
- void seektest();
-
- int main(int argc, char **argv)
- {
- int i;
-
- for(i=0; i<argc; i++)
- printf("%d %s; ",i,argv[i]);
-
- f1(); f2();
- seektest();
- }
-
-
- void f1()
- {
- int ifile, ofile, bytes;
- char mybuf[110];
-
- ifile= open("grammar",O_RDONLY);
- if(ifile == -1) { printf("bad ifile\n"); exit(0); }
-
- ofile= creat("newfile.txt");
- if(ofile == -1) { printf("bad ofile\n"); exit(0); }
-
- while((bytes=read(ifile,mybuf,100)) > 0)
- {
- write(ofile,mybuf,bytes);
- }
-
- close(ifile);
- return;
- }
-
-
- void f2()
- {
- FILE *fin, *fout;
- char mybuf[110];
-
- fin=fopen("grammar","r");
- fout=fopen("newfile.txt","a");
-
- if(fin==NULL || fout==NULL) { printf("f2 bad file\n"); exit(0); }
-
- fgets(mybuf,100,fin);
-
- while(!feof(fin))
- {
- fputs(mybuf,fout);
- fgets(mybuf,100,fin);
- }
-
- fclose(fin); fclose(fout);
- return;
- }
-
- char mybuf2[64];
-
-
- void seektest()
- {
- int h;
- long ls;
-
- h = open("filetwo.c", O_RDONLY);
- ls = lseek( h, 0L, SEEK_END );
- printf( "seekend=%ld\n", ls);
- close(h);
- }
-